package com.zjh.photoshopstudy.app.download;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.lzy.okserver.OkDownload;
import com.lzy.okserver.task.XExecutor;
import com.zjh.photoshopstudy.R;

public class DownloadingActivity extends AppCompatActivity implements XExecutor.OnAllTaskEndListener {
    private DownloadingAdapter adapter;
    private OkDownload okDownload;
    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_downloading);
        textView = findViewById(R.id.textView5);
        Toolbar toolbar = findViewById(R.id.toolbar3);
        okDownload = OkDownload.getInstance();
        RecyclerView recyclerView = findViewById(R.id.video_downloading);
        adapter = new DownloadingAdapter(this);
        adapter.addOnAllTaskEndListener(this);
        if (getIntent().getStringExtra("type").equals("video")) {
            adapter.updateData(DownloadingAdapter.TYPE_VIDEO);
            toolbar.setTitle("下载中视频");
        } else {
            adapter.updateData(DownloadingAdapter.TYPE_MATERIA);
            toolbar.setTitle("下载中素材");
        }
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));


        if (adapter.getItemCount() > 0) {
            textView.setVisibility(View.INVISIBLE);
        }

    }

    @Override
    protected void onResume() {
        super.onResume();
        adapter.notifyDataSetChanged();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        adapter.unRegister();
    }

    @Override
    public void onAllTaskEnd() {
        textView.setVisibility(View.VISIBLE);
    }
}
